package com.zhongwang.mms.module.jiaGongSemi.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.half.model.HInBillModel;
import com.zhongwang.mms.module.half.service.FinishInWarService;
import com.zhongwang.mms.module.half.service.HBasicService;
import com.zhongwang.mms.module.half.service.InBuyWarService;
import com.zhongwang.mms.module.jiaGongSemi.model.JSemiInBillModel;
import com.zhongwang.mms.module.jiaGongSemi.service.SemiInService;
import com.zhongwang.mms.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description:毛坯件入库控制层
 * @author: th
 * @time: 2020/3/21 9:34
 */
@Controller
@RequestMapping("/semiInto")
public class SemiInController extends BaseController {


    @Autowired
    private FinishInWarService finishInWarService;
    @Autowired
    private InBuyWarService inBuyWarService;
    @Autowired
    private HBasicService HBasicService;
    @Autowired
    private SemiInService semiInService;

    /**
     * 毛坯件页面
     *
     * @param model
     * @return
     */
    @GetMapping("/page")
    public String create(Model model) {

        // 获取登入用户实体
        User user = ShiroUtils.getUser();
        model.addAttribute("dept", HBasicService.getDept());
        model.addAttribute("warInfo", semiInService.getWarInfo());
        model.addAttribute("userName", user.getName());
        model.addAttribute("odrDate", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        return "jiaGongSemi/semiIn/page";
    }

    /**
     * 创建外购/外协入库单保存
     *
     * @param jSemiInBillModel
     * @return
     */
    @ResponseBody
    @PostMapping("/create")
    public JsonResult create(@RequestBody JSemiInBillModel jSemiInBillModel) {

        return semiInService.saveSemiBillModel(jSemiInBillModel);
    }

    /**
     * 获取仓库列表
     * @param
     * @return
     */
    @ResponseBody
    @PostMapping("/warehouseInfo")
    public JsonResult warehouseInfo(){

        return jsonResult(semiInService.getWarInfo());
    }
}
